﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using BLL;

namespace TieuLuanWindowsNC
{
    public partial class frmSuaKH : Form
    {
        public static KhachHang kh;
        QLKSEntities db = new QLKSEntities();
        KhachHangBLL khBLL = new KhachHangBLL();

        public frmSuaKH()
        {
            InitializeComponent();
        }

        private void btnSuaKHTrongPhong_Click(object sender, EventArgs e)
        {
            if (khBLL.suaKH(kh.MaKH, txtName.Text, txtAddress.Text, bool.Parse(cboSex.SelectedValue.ToString()), txtPhone.Text, txtCMND.Text, cboMaPhong_Sua.SelectedValue.ToString(), cboMaLK.SelectedValue.ToString()))
            {
                MessageBox.Show("tfuyguy");
                DialogResult = DialogResult.OK;
                
            }
            //this.Close();
            else
            {
                MessageBox.Show("Loi khi sua Khach Hang");
            }
        }

        private void btnClearSuaKH_Click(object sender, EventArgs e)
        {
            txtName.Clear();
            txtAddress.Clear();
            txtPhone.Clear();
            txtCMND.Clear();
        }

        private class GT
        {
            public bool maGT { get; set; }
            public string tenGT { get; set; }
        }

        private void frmSuaKH_Load(object sender, EventArgs e)
        {
            cboMaPhong_Sua.DataSource = db.Phongs.ToList();
            cboMaPhong_Sua.DisplayMember = "MaPhong";
            cboMaPhong_Sua.ValueMember = "MaPhong";

            //tao cboGioitinh
            GT gioitinhNam = new GT();
            gioitinhNam.maGT = true;
            gioitinhNam.tenGT = "Nam";

            GT gioitinhNu = new GT();
            gioitinhNu.maGT = false;
            gioitinhNu.tenGT = "Nữ";

            List<GT> lstGT = new List<GT>();
            lstGT.Add(gioitinhNam);
            lstGT.Add(gioitinhNu);

            cboSex.DataSource = lstGT;
            cboSex.DisplayMember = "tenGT";
            cboSex.ValueMember = "maGT";

            cboMaLK.DataSource = db.LoaiKhaches.ToList();
            cboMaLK.DisplayMember = "TenLK";
            cboMaLK.ValueMember = "MaLK";

            string tenKH = kh.TenKH;
            string diaChi = kh.DiaChi;
            bool gioiTinh = kh.GioiTinh;
            string sdt = kh.SDT;
            string soCMND = kh.SoCMND;
            string maPhong = kh.MaPhong;
            string maLK = kh.MaLK;

            txtName.Text = tenKH;
            txtAddress.Text = diaChi;
            cboSex.SelectedValue = gioiTinh;
            txtAddress.Text = diaChi;
            txtPhone.Text = sdt;
            txtCMND.Text = soCMND;
            cboMaPhong_Sua.SelectedValue = maPhong;
            cboMaLK.SelectedValue = maLK;
        }
    }
}
